<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>

<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <h3 class="text-center">攻坚办的攻坚任务</h3>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">
                            <button class="btn btn-sm btn-info" id="query">条件搜素</button>
                            <button class="btn btn-sm btn-success" id="create">新增攻坚任务</button>
                            <button class="btn btn-sm btn-info hidden" id="detail">查看详情</button>
                            <button class="btn btn-sm btn-warning hidden" id="update">修改</button>
                            <button class="btn btn-sm btn-danger" id="delete">删除任务</button>
                            <button class="btn btn-sm btn-success hidden" id="exportTask">导出Excel</button>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <h3 class="text-center" style="margin-top: 100px">督察组的攻坚任务</h3>
                <div class="row" >
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable2"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager2"></div>
                    </div><!-- /.col -->
                </div><!-- /.page-content -->
            </div>
        </div>
    </div><!-- /.main-content -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<script type="text/javascript">
    // 基本路径
    var baseUrl = "<s:url value="/taskCrucial/"></s:url>"

    // jqgrid的表格高度
    var height = 320;
    // jqgrid表格行头的中文
    //var colNames = ['', '任务名称', "任务内容", "事项类型","督查组单位","接收状态","操作"];
    var colNames = ['', '任务名称', "任务内容","督查组单位","附件","状态","操作"];
    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'mainName', index: 'mainName', width: 250, editable: true},
        {name: 'content', index: 'content', width: 250, editable: true},
        // {name: 'categoryId', index: 'categoryId', width: 250, editable: true, formatter: categoryIdFormatter},
        {name: 'inspectionId', index: 'inspectionId', width: 250, editable: true},
        {name: 'file', index: 'file', width: 250, editable: true,formatter:fileFormatter},
        {name: 'status', width: 150, editable: true,formatter:statusFormatter},
        {name : 'sy', width : 150, align : "center",formatter:urgentFormatter}
    ];
    function urgentFormatter(value, grid, rows, state) {
        console.log(grid, rows, state);
        grid.colModel.title=false
        var html = "<div style='color: #049CE6;display: flex;justify-content: center'>"
        if(rows.createUser !=undefined && rows.crucialUser != undefined) {
            if (rows.createUser == rows.crucialUser) {
                html += "<div style='width: 40px;cursor: pointer' title='催办'>催办</div>"
            } else {
                html += "<div style='width: 40px;cursor: pointer' title='查看'>查看</div>"
            }
        }
        html += "</div>"
        return  html;

    }
    function statusFormatter(value, grid, rows, state) {
        console.log(grid, rows, state);
        grid.colModel.title=false
        if(rows.createUser !=undefined && rows.crucialUser != undefined) {
            if (rows.createUser == rows.crucialUser) {
                return "待立项"
            } else {
                return "已立项"
            }
        } else {
            return "未知"
        }
    }

    /**
     * 附件格式化
     */
    function fileFormatter(data) {
        if (data == null || data == "") {
            return "无任务附件";
        } else {
            return '<input type="button" value="下载" onclick="downDetail(\'' + data + '\')" \n' +
                ' style="width: 100%; height: 32px;" class="btn-large btn-primary"/>';
        }
    }

    //下载按钮
    function downDetail(id) {
        var url = "/filesUpload/download/" + id;
        window.open(url);
    }

    /**
     * 任务类型格式化
     */
    function categoryIdFormatter(data) {
        var mz = '';
        $.ajax({
            url:"/taskMain/categoryName/"+data,
            type:"get",
            dataType:'json',
            async:false,
            success:function (data) {
                mz = data.category;
            }
        })
        return mz;
    }

    var rowIds,rowids=[];
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }
    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };

    //jqgrid的具体执行方法
    jqgrid({
        shrinkToFit: false,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        autoScroll: false,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid
            var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
            var type = selectedRowValue.categoryId; //事项类型
            console.log('当前事项类型：'+ type)
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i< rowids.length; i++){
                    if(rowids[i] ==  rowid){
                        flag = true;
                        continue;
                    }
                }
                if(!flag){
                    gridAddSelect(rowid);
                }
            }
        },
        onSelectAll:function (aRowids,status){
            if (!status) {
                aRowids.forEach(function(value,index){
                    gridRemoveSelect(value);
                });
            } else {
                aRowids.forEach(function(value,index){
                    var flag = false;
                    for (var i = 0; i< rowids.length; i++){
                        if(rowids[i] ==  value){
                            flag = true;
                            continue;
                        }
                    }
                    if(!flag){
                        gridAddSelect(value);
                    }
                });
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        },
        ondblClickRow:function (rowid) {
            console.log('db  click')
        }
    });


    $("#create").click(function(){
        parent.openapp("/taskCrucial/create", "createTaskCrucial", "新增攻坚任务")
    });

    /***************************  督察组显示  ************************************/
    var colNames2 = ['', '任务名称', "事项类型", "状态", "办理时限", "状态说明", "逾期说明", "操作"];

    var colModel2 = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'mainName', index: 'mainName', width: 250, editable: true},
        {name: 'categoryId', index: 'categoryId', width: 250, editable: true, formatter: categoryIdFormatter},
        {name: 'status', index: 'status', width: 150, editable: true, formatter: typeFormatter},
        {name: 'timeLimit', index: 'timeLimit', width: 150, editable: true},
        {name: 'typeExplain', index: 'typeExplain', width: 350, editable: true},
        {name: 'overdueExplain', index: 'overdueExplain', width: 250, editable: true},
        {name: 'sy', width: 150, align: "center", formatter: feedbackBtnFormatter}
    ];
    var url2 = "<s:url value="/taskMain/noDoneMain/"></s:url>"
    jqgrid({
        url: url2,
        gridTableId: "#gridTable2",
        gridPagerId: "#gridPager2",

    })


    /**
     * 任务状态格式化
     */
    function typeFormatter(data) {
        switch (data) {
            case '0':
                return '待审批';
                break;
            case '1':
                return '审批未通过';
                break;
            case '2':
                return '正常';
                break;
            case '3':
                return '新反馈';
            case '4':
                return '已完成';
            default:
                return '未知';
        }
    }

    function feedbackBtnFormatter(value, grid, rows, state) {
        grid.colModel.title = false;
        return "<div style='color: #049CE6;display: flex;justify-content: center'>" +
            "<div style='width: 40px;cursor: pointer' title='查看'id='feedbackBtn'>查看</div>" +
            "<div class='approval' style='width: 40px;border-left:1px solid #049CE6;cursor: pointer; display: "+ (rows.status == 0 ? "block" : "none" )  +"' title='审批'>审批</div>" +
            // "<div style='border-left:1px solid #049CE6;border-right:1px solid #049CE6;width: 40px;cursor: pointer; display: "+ (rows.status != 0 ? "block" : "none" ) +"'title='修改'>修改</div>" +
            // "<div style='width: 40px;cursor: pointer;display: "+ (rows.status != 0 ? "block" : "none" ) +"' title='删除'>删除</div>" +
            "</div>";
    }
</script>
</body>
</html>
